class Geotag < ActiveRecord::Base
  has_and_belongs_to_many :posts

  def self.find_or_create(name)
    tag = self.find_by_name(name)
    if tag.nil?
      results = Geocoding::get(name)
      if results.status == Geocoding::GEO_SUCCESS        
        tag = Geotag.new :name => name, :longitude => results[0].longitude, :latitude => results[0].latitude
        tag.save!
      end
    end
    tag
  end
  
end
